package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;

import com.itheima.constant.MessageConstant;
import com.itheima.dao.MemberDao;
import com.itheima.entity.Result;
import com.itheima.pojo.Member;
import com.itheima.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

/*
 *@AUTHOR:LIUCHAO;
 *@DATE: 2020/9/16 11:02
 */
@Service(interfaceClass = LoginService.class)
public class LoginServiceImpl implements LoginService {

    @Autowired
    private MemberDao memberDao;
    @Override
    public Result checkMember(String telephone) {
        /*此时我设置的是用户登录,而不是后台人员登录,所以用户没有存在会员
        * 我就注册一个,放行,  存在,就直接登录*/
        Integer count =memberDao.checkPhoneNumber(telephone);
        Member member =null;
        if (count==null){
             member = new Member();
            member.setPhoneNumber(telephone);
            member.setRegTime(new Date());
            memberDao.add(member);
        }
        /*此时已经登录成功,  写入Cookie.跟着用户,用以后面进行session跟踪,返回到controller层去进行cookie的tianjia
        * cookie需要httpResponse的支持*/


        return new Result(true, MessageConstant.LOGIN_SUCCESS,member);
    }
}
